#include<bits/stdc++.h>
using namespace std;
int n;
int a[1114514];
int dfs(int dep,int lastr,int lastb){
	if(dep==n){
		if(lastb==-1||lastr==-1)return (a[dep-1]==a[dep])*a[dep];
		else
			return max((a[lastr]==a[dep]),(a[lastb]==a[dep]))*a[dep];
	}
	//choose
	int rans=dfs(dep+1,dep,lastb)+(a[lastr]==a[dep])*a[dep];
	int bans=dfs(dep+1,lastr,dep)+(a[lastb]==a[dep])*a[dep];
	return max(rans,bans);
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(0);
	cout.sync_with_stdio(0);
	int T;
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		cout<<dfs(1,-1,-1)<<endl;
	}
	return 0;
}
	
